//
// Created by user on 2022/3/1.
//
#include <vector>
#include <stack>
using namespace std;
vector<int> dailyTemperatures(vector<int>& temperatures) {
    int n = temperatures.size();
    if(n==1)return vector<int>(1,0);
    vector<int> ans(n, 0);
    stack<int> st1;
    for (int i = 0; i < n; ++i) {

        int x = temperatures[i];
        while (!st1.empty() && x>temperatures[st1.top()]){
            int preIndex = st1.top();
            ans[preIndex] = i-preIndex;
            st1.pop();
        }
        st1.push(i);
    }

    return ans;
}